import React from 'react';
import { Row, Col, Form, Input, Button, InputNumber } from 'antd';
import { WhseSelect } from '@/components/FormItemSelect';
import PartSelect from '@/components/PartSelect';

const FormItem = Form.Item;

const formLayout = {
  labelCol: { span: 6 },
  wrapperCol: { span: 14 },
};

export default class InvADJModal extends React.Component<any, any> {
  formRef: any = React.createRef();
  handleSubmit = (values: any) => {
    const { onSubmit } = this.props;
    if (typeof onSubmit === 'function') {
      onSubmit(values);
    }
  };
  setCurrent = (part?: any) => {
    var PartBOM: any = {};
    PartBOM.partNum = part.partNum;
    PartBOM.partDescription = part.partDescription;
    PartBOM.ium = part.ium;
    this.formRef.current.setFieldsValue(PartBOM);
  };
  componentDidMount() {
    const { formVals } = this.props;
    if (formVals) {
      this.formRef.current.setFieldsValue(formVals);
      this.setState({ loading: false });
    }
  }
  formRender = () => {
    const { formVals = {} } = this.props;

    return (
      <Form
        {...formLayout}
        ref={this.formRef}
        initialValues={formVals}
        onFinish={this.handleSubmit}
      >
        <Row gutter={16}>
          <Col span={24}>
            <FormItem label="物料编码">
              <PartSelect
                name="partNum"
                noStyle
                width={200}
                required={true}
                placeholder="物料编码"
                setCurrent={this.setCurrent}
              />
            </FormItem>
          </Col>
          <Col span={24}>
            <WhseSelect label="仓库" showSearch={false} name={'warehouseCode'} placeholder="仓库" />
          </Col>
          <Col span={24}>
            <FormItem name="binNum" label="库位">
              <Input placeholder="请输入库位" disabled />
            </FormItem>
          </Col>
          <Col span={24}>
            <FormItem name="onhandQty" label="现存量">
              <Input placeholder="请输入现存量" disabled />
            </FormItem>
          </Col>
          <Col span={24}>
            <FormItem name="lotNum" label="调整批次">
              <Input placeholder="请输入批次" disabled />
            </FormItem>
          </Col>
          <Col span={24}>
            <WhseSelect
              label="调整到仓库"
              showSearch={false}
              name={'toWhseCode'}
              placeholder="调整到仓库"
            />
          </Col>
          <Col span={24}>
            <FormItem
              name="toBinNum"
              label="调整到库位"
              rules={[{ required: true, message: '请输入库位' }]}
            >
              <Input placeholder="请输入调整到库位" />
            </FormItem>
          </Col>
          <Col span={24}>
            <FormItem
              name="qty"
              label="调整数量"
              rules={[{ required: true, message: '请输入数量' }]}
            >
              <InputNumber placeholder="请输入调整数量" min={0} />
            </FormItem>
          </Col>
          <Col span={24}>
            <FormItem name="reason" label="调整原因">
              <Input placeholder="请输入调整原因" />
            </FormItem>
          </Col>
          <Col span={24} style={{ display: 'flex', justifyContent: 'center' }}>
            <Button type="primary" htmlType="submit">
              确认
            </Button>
          </Col>
        </Row>
      </Form>
    );
  };
  render() {
    const FormRender = this.formRender;

    return <FormRender />;
  }
}
